;;;Place text on polyline or line.  (uses MKLAYR GETSTYLE USTR)
;;;
;;;	AUTHOR: HENRY C. FRANCIS
;;;		425 N. ASHE ST.
;;;		SOUTHERN PINES, NC 28387
;;;              
;;;		All rights reserved without prejudice.
;;;	Copyright:	1994-2011
;;;	Edited:		4/27/2011
;;;
(DEFUN C:LTXT ( / bkp1b bkp1m bkp1r bkp1l bkp1a bkp2b bkp2m bkp2r bkp2l
bkp2a bkp3b bkp3m bkp3r bkp3l bkp3a ltxt_thts)
(if getstyle (getstyle "A")(progn (load "getstyle")(getstyle "A")))
  (IF ustr NIL (LOAD "ustr" "\nFile USTR.LSP not loaded! "))
  (IF ukword NIL (LOAD "ukword" "\nFile UKWORD.LSP not loaded! "))
  (setq sytxt (ustr 1 "Enter text" (IF old_sytxt old_sytxt sytxt) "T"))
  (SETQ old_sytxt sytxt)
  (if c:mklayr nil (load"mklayr" "\nFile MKLAYR.LSP not loaded! "))
  (c:svlayr)
  (setq modf "NOTE")
  (if gvpno nil (load"gvpno" "\nFile GVPNO.LSP not loaded! "))
  (gvpno)
  (if dimscl nil (load"dimscl" "\nFile DIMSCL.LSP not loaded! "))
  (dimscl)
  (IF txtsize
    NIL
    (LOAD "txtsize" "\nFile TXTSIZE.LSP not loaded! ")
  ) ;_ end of IF
  (if do_exist
    (SETQ exornw "Existing")
    (IF (AND exornw (WCMATCH exornw "Existing"))
      (SETQ do_exist T)
      (IF exornw NIL
        (setq exornw (ukword 1 "Existing New" "Label <E>xisting or <N>ew lines? " exornw))
      )
    )
  )
  (IF (WCMATCH exornw "Existing")
    (SETQ do_exist T)
    (SETQ do_exist NIL)
  )
  (IF ltxt_thts
    NIL
    (PROGN
      (txtsize nil)
      (SETQ ltxt_thts thts
            colr txcolr
      )
    )
  )
  (while
    (setq sel1 (nentselp "\nSelect line"))
    (IF
      (OR
        (WCMATCH (cdr(assoc 8(entget(car sel1)))) "*|?[CN]????[0-9A-Z]*");modified CLG centerline layer (2nd character modification C or N are linetypes center and center2 respectively. 7th character is modification for color)
        (WCMATCH (cdr(assoc 8(entget(car sel1)))) "*|CENTERLINE*");xref layer named "CENTERLINE"
      )
      (PROGN
        (txtsize "140")
        (SETQ colr "4")
        (IF old_sytxt (SETQ sytxt old_sytxt))
        (setq txtobl 0.0)
        (setq llt "-")
        (PRINC "\nFixed height=140(Leroy), oblique=0, and color=4 overides are used for road labels. (Requires selected object on a centerline layer)")
        (PRINC)
      )
      (cond
        ((eq exornw "Existing")
          (setq txtobl 0.2618)
          (setq llt "E")
        )
        ((eq exornw "New")
          (setq txtobl 0.0)
          (setq llt "-")
        )
      )
    )
    (if (= "LINE" (cdr(assoc 0(entget(car sel1)))))
    (progn
      (setq endp1 (trans(cdr(assoc 10(entget(car sel1)))) 0 1)
            endp1 (list(car endp1)(cadr endp1)))
      (setq endp2 (trans(cdr(assoc 11(entget(car sel1)))) 0 1)
            endp2 (list(car endp2)(cadr endp2)))
      (setq lang (angle endp1 endp2))
      (setq chkang (+ lang (getvar"viewtwist")))
      (if
        (or
          (and(> chkang 1.868)(< chkang 5.01))
          (and(> chkang (+(* 2 pi)1.868))(< chkang (+(* 2 pi)5.01)))
        )
        (setq tang (+ pi lang))
        (setq tang lang)
      );if
;;;      (setq templ 125)
;;;      (setq txtht (*(/ templ 1000.00)dimsc))
      (setq pt1 (polar endp1 (angle endp1 endp2)(distance endp1(cadr sel1))))
      (setq sytln (*(strlen sytxt)txtht))
;;;      (setq colr "2")
    );progn
    (progn
      (setq endp1 (trans(cdr(assoc 10(entget(car sel1)))) 0 1))
      (setq endp2 (trans(cdr(assoc 10(entget(entnext(car sel1))))) 0 1))
      (setq lang (angle endp1 endp2))
      (setq chkang (+ lang (getvar"viewtwist")))
      (if
        (or
          (and(> chkang 1.868)(< chkang 5.01))
          (and(> chkang (+(* 2 pi)1.868))(< chkang (+(* 2 pi)5.01)))
        )
        (setq tang (+ pi lang))
        (setq tang lang)
      );if
;;;      (setq templ 125)
;;;      (setq txtht (*(/ templ 1000.00)dimsc))
      (setq pt1 (polar endp1 (angle endp1 endp2)(distance (list(car endp1)(cadr endp1))(cadr sel1))))
      (setq sytln (*(strlen sytxt)txtht))
    );progn
    );if
    (c:mklayr)
    (setq txtlst
      (list
        (cons 0 "TEXT")
        (cons 1 sytxt)
        (cons 10 pt1)
        (cons 11 pt1)
        (cons 40 txtht)
        (cons 50 tang)
        (cons 51 txtobl)
        (cons 7 (getvar"textstyle"))
        (cons 72 1)
        (cons 73 2)
      )
    )
    (entmake txtlst)
    (setq oldsel sel1)
  );while
  (c:rslayr)
  (getstyle "")
;  (setq sytxt nil)
  (princ)
);defun
